/* GUI CONVERTED from recwomt.p (converter v1.75) Tue Jun  5 16:00:18 2001 */
/* recwomt.p - CUMULATIVE REPETITIVE ORDER MAINTENANCE                        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.8.1.4 $                                                           */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94           BY: WUG *GN77*        */
/* REVISION: 7.3      LAST MODIFIED: 11/03/94           BY: WUG *GN98*        */
/* REVISION: 7.3      LAST MODIFIED: 03/05/95           BY: WUG *G0GK*        */
/* REVISION: 8.5      LAST MODIFIED: 04/03/95           BY: tjs *J027*        */
/* REVISION: 7.3      LAST MODIFIED: 11/14/95           BY: rvw *G1CZ*        */
/* REVISION: 7.3      LAST MODIFIED: 01/17/96           BY: flm *G1JB*        */
/* REVISION: 8.5      LAST MODIFIED: 06/05/96           BY: jym *G1VW*        */
/* REVISION: 8.5      LAST MODIFIED: 06/19/96           BY: taf *J0V0*        */
/* REVISION: 8.5      LAST MODIFIED: 01/17/97   BY: *G2JV* Julie Milligan     */
/* REVISION: 8.5      LAST MODIFIED: 04/29/97   BY: *G2MM* Julie Milligan     */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 04/07/98   BY: *J2DD* Kawal Batra        */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 06/06/00   BY: *L0YT* Vandna Rohira      */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.8.1.4 $    BY: Hualin Zhong  DATE: 05/30/01 ECO: *N0YY*          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE recwomt_p_2 "Start Eff"
/* MaxLen: Comment: */

&SCOPED-DEFINE recwomt_p_3 "End Eff"
/* MaxLen: Comment: */

&SCOPED-DEFINE recwomt_p_4 "Created"
/* MaxLen: Comment: */

&SCOPED-DEFINE recwomt_p_5 "Comments"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define buffer simstr for si_mstr.
define buffer womstr for wo_mstr.
define new shared variable any_issued like mfc_logical.
define new shared variable cmtindx like wo_cmtindx.
define new shared variable comp like ps_comp.
define new shared variable del-yn like mfc_logical initial no.
define new shared variable deliv like wod_deliver.
define new shared variable eff_date as date.
define new shared variable leadtime like pt_mfg_lead.
define new shared variable new_wo like mfc_logical initial no.
define new shared variable prev_due like wo_due_date.
define new shared variable prev_qty like wo_qty_ord.
define new shared variable prev_release like wo_rel_date.
define new shared variable prev_site like wo_site.
define new shared variable prev_status like wo_status.
define new shared variable qty like wo_qty_ord.
define new shared variable undo_all like mfc_logical no-undo.
define new shared variable wo_recno as recid.
define new shared variable del-joint like mfc_logical initial no.
define variable cur_mthd like cs_method no-undo.
define variable cur_set like cs_set no-undo.
define variable find_date as date no-undo.
define variable forwards as integer no-undo.
define variable glx_mthd like cs_method no-undo.
define variable glx_set like cs_set no-undo.
define variable i as integer no-undo.
define variable interval as integer no-undo.
define variable know_date as date no-undo.
define variable msg-type as integer no-undo.
define variable new_end_date as date no-undo.
define variable new_start_date as date no-undo.
define variable nonwdays as integer no-undo.
define variable old_end_date as date no-undo.
define variable old_start_date as date no-undo.
define variable overlap as integer no-undo.
define variable prev_bomcode like wo_bom_code no-undo.
define variable prev_mthd like cs_method no-undo.
define variable prev_routing like wo_routing no-undo.
define variable ptstatus like pt_status no-undo.
define variable wocmmts like woc_wcmmts label {&recwomt_p_5} no-undo.
define variable wolot like wo_lot no-undo.
define variable wonbr like wo_nbr no-undo.
define variable workdays as integer no-undo.
define variable yn like mfc_logical initial no no-undo.
define variable site like wo_site no-undo.
define variable part like wo_part no-undo.
define variable routing like wo_routing no-undo.
define variable bom_code like wo_bom_code no-undo.
define variable prline like wo_line no-undo.
define variable cumwo_lot as character no-undo.
define variable ok like mfc_logical no-undo.
define variable prompt-routing like mfc_logical no-undo.
define variable not_def like mfc_logical.
assign not_def = no.

run find-mfcctrl (input-output not_def).
if not_def then leave.

find first woc_ctrl no-lock no-error.

assign
   site = global_site
   part = global_part
   eff_date = today.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
wo_lot         colon 25
   skip(1)
   wo_site        colon 25
   wo_part        colon 25
   pt_desc1       at 47 no-label
   wo_line        colon 25
   ln_desc        at 47 no-label
   wo_routing     colon 25
   wo_ord_date    colon 54 label {&recwomt_p_4}
   wo_bom_code    colon 25
   wo_status      colon 54
   skip(1)
   wo_rel_date    colon 25 label {&recwomt_p_2}
   wo_due_date    colon 25 label {&recwomt_p_3}
   skip (1)
   wocmmts        colon 25
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

view frame a.

mainloop:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

   assign
      prev_status = ""
      prev_release = ?
      prev_due = ?
      prev_qty = 0
      leadtime = 0
      new_wo = no.

   prompt-for wo_lot with frame a
   editing:
      {mfnp05.i wo_mstr wo_type_nbr "wo_type = ""C"" and wo_nbr = """""
                wo_lot "input wo_lot"}

      if recno <> ? then do:
         find pt_mstr where pt_part = wo_part no-lock.

         if wo_cmtindx > 0
            or (available woc_ctrl and woc_wcmmts) then
            wocmmts = yes.
         else
            wocmmts = no.

         display
            wo_lot
            wo_site
            wo_part
            pt_desc1
            wo_line
            wo_routing
            wo_bom_code
            wo_ord_date
            wo_rel_date
            wo_status
            wo_due_date
            wocmmts
         with frame a.

         find ln_mstr no-lock
         where ln_site = wo_site and ln_line = wo_line no-error.
         if available ln_mstr then display ln_desc.
         else display "" @ ln_desc.

      end.
   end.

   find wo_mstr no-lock using wo_lot no-error.
   /* ORDER IS NOT A CUMULATIVE ORDER */
   if available wo_mstr and (wo_type <> "C" or wo_nbr <> "") then do:
      {pxmsg.i &MSGNUM=555 &ERRORLEVEL=3}
      undo , retry.
   end.

   if available wo_mstr then do:
      /* CHECK FOR USERS ACCESS TO SITE */
      {gprun.i ""gpsiver.p"" "(input  wo_site,
                               input  ?,
                               output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if return_int = 0
      then do:
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         /*USER DOES NOT HAVE ACCESS TO THIS SITE*/
         next-prompt wo_site.
         undo, retry.
      end.
   end.

   /* REFERENCE CUSTOM PROGRAM TO CREATE CIM FILE FOR USE WITH THIS PROGRAM */
   if false then do:
      {gprun.i ""recimrp.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
   /* NO TRANSACTION SHOULD BE PENDING HERE */
   {gprun.i ""gpistran.p"" "(input 1, input """")"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if not available wo_mstr and input wo_lot <> "" then do:
      {pxmsg.i &MSGNUM=6010 &ERRORLEVEL=3}
      undo , retry.
   end.
   else if not available wo_mstr then do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

      /* ADD NEW RECORD */
      {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
      clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
      display
         site @ wo_site
         part @ wo_part
         prline @ wo_line
         today @ wo_rel_date
         today @ wo_ord_date.
      seta:
      do with frame a on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         /* GET SITE, ITEM, PRODUCTION LINE */
         prompt-for wo_site wo_part wo_line with frame a
         editing:
            if frame-field = "wo_site" then do:
               /* FIND/NEXT PREVIOUS */
               {mfnp.i si_mstr wo_site si_site wo_site si_site si_site}
               if recno <> ? then do:
                  display si_site @ wo_site.
               end.
            end.
            else if frame-field = "wo_part" then do:
               /* FIND NEXT/PREVIOUS */
               {mfnp.i pt_mstr wo_part pt_part wo_part pt_part pt_part}
               if recno <> ? then
                     display pt_part @ wo_part pt_desc1 with frame a.
            end.
            else if frame-field = "wo_line" then do:
               /* FIND/NEXT PREVIOUS */
               {mfnp05.i lnd_det lnd_line
                  "lnd_site = input wo_site and lnd_part = input wo_part"
                  lnd_line "input wo_line"}
               if recno <> ? then do:
                  find ln_mstr no-lock
                  where ln_line = lnd_line and ln_site = lnd_site no-error.
                  display lnd_line @ wo_line.
                  if available ln_mstr then display ln_desc.
               end.
            end.
            else do:
               readkey.
               apply lastkey.
            end.
         end.
         assign
            site   = input wo_site
            part   = input wo_part
            prline = input wo_line.

         /* VALIDATE SITE */
         find si_mstr no-lock where si_site = site no-error.
         if not available si_mstr then do:
            {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3} /* SITE DOES NOT EXIST */
            next-prompt wo_site.
            undo, retry.
         end.
         else if si_db <> global_db then do:
            {pxmsg.i &MSGNUM=5421 &ERRORLEVEL=3}
            /* SITE IS NOT ASSIGNED TO THIS DATABASE */
            next-prompt wo_site.
            undo, retry.
         end.

         /* CHECK FOR USERS ACCESS TO SITE */
         {gprun.i ""gpsiver.p"" "(input site,
                                  input ?,
                                  output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if return_int = 0 then do:
            {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
            /*USER DOES NOT HAVE ACCESS TO THIS SITE*/
            next-prompt wo_site.
            undo, retry.
         end.

         /* VALIDATE ITEM */
         find pt_mstr no-lock where pt_part = part no-error.
         if available pt_mstr then do:
            assign
               ptstatus = pt_status
               substring(ptstatus,9,1) = "#".
            if can-find(isd_det where isd_status = ptstatus
               and isd_tr_type = "ADD-RE") then do:
               /* RESTRICTED PROCEDURE FOR ITEM STATUS CODE */
               {pxmsg.i &MSGNUM=358 &ERRORLEVEL=3 &MSGARG1=pt_status}
               next-prompt wo_part.
               undo, retry.
            end.
            assign
               routing  = pt_routing
               bom_code = pt_bom_code.
            find ptp_det no-lock
            where ptp_part = part and ptp_site = site no-error.
            if available ptp_det then
               assign
                  routing  = ptp_routing
                  bom_code = ptp_bom_code.
         end.
         else do:
            {pxmsg.i &MSGNUM=17 &ERRORLEVEL=3}
            next-prompt wo_part.
            undo, retry.
         end.

         /* VERIFY PRODUCTION LINE AND SITE */
         find first ln_mstr no-lock where ln_site = site no-error.
         if available ln_mstr or prline <> "" then do:
            find ln_mstr no-lock
            where ln_line = prline and ln_site = site no-error.
            if not available ln_mstr then do:
               {pxmsg.i &MSGNUM=8526 &ERRORLEVEL=3}
               next-prompt wo_line.
               undo,retry.
            end.
            else display ln_desc.
            find first lnd_det no-lock
            where lnd_line = prline
                  and lnd_site = site
                  and lnd_part = part no-error.
            if not available lnd_det then do:
               {pxmsg.i &MSGNUM=8527 &ERRORLEVEL=3}
               next-prompt wo_line.
               undo,retry.
            end.
         end.
         else display "" @ ln_desc.
         display
            site @ wo_site
            routing @ wo_routing
            bom_code @ wo_bom_code.
         assign
            global_site = site
            global_part = part.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

      setb:
      do with frame a on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         /* GET ROUTING & BOM CODE FROM USER */
         prompt-for
            wo_routing
            wo_bom_code
            wo_rel_date
         with frame a
         editing:
            if frame-field = "wo_routing" then do:
               {mfnp05.i ptr_det ptr_part
                  "ptr_part = part and ptr_site = site"
                  ptr_routing "input wo_routing"}
               if recno <> ? then do:
                  display ptr_routing @ wo_routing.
                  recno = ?.
               end.
            end.
            else
               if frame-field = "wo_bom_code" then do:
               {mfnp05.i ptr_det ptr_part
                  "ptr_part = part and ptr_site = site
                        and ptr_routing = input wo_routing"
                  ptr_bom_code "input wo_bom_code"}
               if recno <> ? then do:
                  display ptr_bom_code @ wo_bom_code.
                  recno = ?.
               end.
            end.
            else do:
               status input.
               readkey.
               apply lastkey.
            end.
         end.
         assign
            routing  = input wo_routing
            bom_code = input wo_bom_code
            eff_date = input wo_rel_date.
         if eff_date = ? then do:
            {pxmsg.i &MSGNUM=27 &ERRORLEVEL=3}
            next-prompt wo_rel_date with frame a.
            undo, retry.
         end.

         /* REPLACE THE CALL FROM rerpmta.p TO wortbmv.p      */
         /* ADD INPUT PARAMETER message number AFTER BOM_CODE */
         /* ADD OUTPUT PARAMETER prompt-routing AFTER ok      */
         {gprun.i ""wortbmv.p"" "(input  part,
                                  input  site,
                                  input  routing,
                                  input  bom_code,
                                  input  3,
                                  output ok,
                                  output prompt-routing)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if not ok then do:
            if prompt-routing then
               next-prompt wo_routing.
            else next-prompt wo_bom_code.
            undo,retry.
         end.

         if input wo_routing = "" and
            not can-find (first ro_det where ro_routing = part)
         then do:
            next-prompt wo_routing.
            /* ROUTING DOES NOT EXISTS */
            {pxmsg.i &MSGNUM=126 &ERRORLEVEL=3}
            undo, retry.
         end.

         /* FIND CUM ORDER. CREATE IT IF IT DOESN'T EXIST */
         {gprun.i ""regetwo.p"" "(input  site,
                                  input  part,
                                  input  eff_date,
                                  input  prline,
                                  input  routing,
                                  input  bom_code,
                                  output cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if cumwo_lot = ? then do:
            yn = yes.
            /* PLEASE CONFIRM UPDATE */
            {pxmsg.i &MSGNUM=32 &ERRORLEVEL=1 &CONFIRM=yn}
            if not yn then undo, retry.
            {gprun.i ""recrtwo.p"" "(input  site,
                                     input  part,
                                     input  eff_date,
                                     input  prline,
                                     input  routing,
                                     input  bom_code,
                                     output cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            display cumwo_lot @ wo_lot.
            find wo_mstr no-lock using wo_lot no-error.
         end.
         else do:
            /* DATES MAY NOT OVERLAP */
            {pxmsg.i &MSGNUM=122 &ERRORLEVEL=3
                     &MSGARG1="getTermLabel(""WITH_WORK_ORDER_ID"",24) +
                              "":"" + cumwo_lot"}
            next-prompt wo_rel_date.
            undo, retry.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* ADD NEW CUMULATIVE ORDER */
   /* ASSIGN DEFAULT VALUES WHEN ADDING NEXT ORDER */
   assign
      site   = wo_site
      part   = wo_part
      prline = wo_line.

   if wo_cmtindx > 0
      or (available woc_ctrl and woc_wcmmts) then
      wocmmts = yes.
   else
      wocmmts = no.

   wo_recno = recid(wo_mstr).
   find pt_mstr where pt_part = wo_part no-lock.

   display
      wo_lot
      wo_site
      wo_part
      pt_desc1
      wo_line
      wo_routing
      wo_bom_code
      wo_ord_date
      wo_rel_date
      wo_status
      wo_due_date
      wocmmts
   with frame a.

   find ln_mstr no-lock where ln_site = wo_site and ln_line = wo_line no-error.
   if available ln_mstr then display ln_desc.
   else display "" @ ln_desc.

   ststatus = stline[2].
   status input ststatus.

   detail-loop:
   do on error undo , retry with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

      find wo_mstr where recid(wo_mstr) = wo_recno exclusive-lock no-error.
      set
         wo_rel_date
         wo_due_date
         wocmmts
         go-on(F5 CTRL-D).

      if lastkey = keycode("F5")
         or lastkey = keycode("CTRL-D")
      then do:

         run find-mph-hist (input wo_lot).

         if wo_status <> "c" then do:
            {pxmsg.i &MSGNUM=536 &ERRORLEVEL=3}
            undo, retry.
         end.

         if wo_wip_tot <> 0 then do:
            /* WIP VALUE NOT ZERO */
            {pxmsg.i &MSGNUM=5120 &ERRORLEVEL=2
                     &MSGARG1=string(wo_wip_tot)}
         end.

         del-yn = yes.
         /* PLEASE CONFIRM DELETE */
         {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
         if del-yn = no then undo, retry.
      end.

      if not del-yn then do:
         if wo_rel_date > wo_due_date then do:
            {pxmsg.i &MSGNUM=4 &ERRORLEVEL=3}
            next-prompt wo_rel_date.
            undo , retry.
         end.

         assign
            new_start_date = wo_rel_date
            new_end_date   = wo_due_date.

         for each womstr no-lock
         where womstr.wo_type = "c"
               and womstr.wo_nbr = ""
               and womstr.wo_part = wo_mstr.wo_part
               and womstr.wo_site = wo_mstr.wo_site
               and womstr.wo_line = wo_mstr.wo_line
               and womstr.wo_routing = wo_mstr.wo_routing
               and womstr.wo_bom_code = wo_mstr.wo_bom_code
               and womstr.wo_lot <> wo_mstr.wo_lot:
/*GUI*/ if global-beam-me-up then undo, leave.

            assign
               old_start_date = womstr.wo_rel_date
               old_end_date   = womstr.wo_due_date.

            if ((new_start_date >= old_start_date or
                 old_start_date = ?) and
                (new_start_date <= old_end_date or
                 old_end_date = ?))
               or ((new_end_date >= old_start_date or
                    old_start_date = ?) and
                   (new_end_date <= old_end_date or
                    old_end_date = ?))
            then do:
               /* DATE RANGES MAY NOT OVERLAP */
               {pxmsg.i &MSGNUM=122 &ERRORLEVEL=3
                        &MSGARG1="getTermLabel(""WITH_WORK_ORDER_ID"",24) +
                                 "":"" + wo_lot"}
               undo detail-loop , retry detail-loop.
            end.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         view frame a.

         if not available woc_ctrl then
         find first woc_ctrl no-lock.

         if wocmmts = yes then do:
            assign
               global_ref = wo_part
               cmtindx    = wo_cmtindx.
            hide frame a no-pause.
            {gprun.i ""gpcmmt01.p"" "(input ""wo_mstr"")"}
/*GUI*/ if global-beam-me-up then undo, leave.

            view frame a.
            wo_cmtindx = cmtindx.
         end.
      end.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if del-yn and wo_wip_tot <> 0 then do:
      /* WIP VALUE NOT ZERO */
      {pxmsg.i &MSGNUM=5120 &ERRORLEVEL=2 &MSGARG1=string(wo_wip_tot)}
   end.

   if del-yn then do:
      {gprun.i ""wowomte.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


      clear frame a no-pause.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
      del-yn = no.
   end.

end.
/*GUI*/ if global-beam-me-up then undo, leave.


status input.

PROCEDURE find-mfcctrl:
   define input-output parameter not_def like mfc_logical.

   find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.
   if not available mfc_ctrl or mfc_logical = false then do:
      assign not_def = yes.
      {pxmsg.i &MSGNUM=5119 &ERRORLEVEL=3}
      message.
      message.
      leave.
   end.
END PROCEDURE.

PROCEDURE find-mph-hist:

   define input parameter inpar_lot like wo_lot.

   /* ISSUE WARNING IF QUALITY TEST RESULTS EXIST FOR THIS W/O      */
   find first mph_hist where mph_lot = inpar_lot no-lock no-error.
   if available mph_hist then do:
      /* QUALITY TEST RESULTS EXIST FOR THIS WORK ORDER FOR ITEM#  */
      {pxmsg.i &MSGNUM=7109 &ERRORLEVEL=2 &MSGARG1=mph_part}
      pause.
   end.

END PROCEDURE.
